<!--
@name:dialongMeasure
@author:Zhenglei
@date:9:37
@description:dialongMeasure
@update:2022/8/129:37
-->
<template>
  <el-dialog :title="title"
             :visible.sync="visible"
             :before-close="modalClose"
             :close-on-click-modal="false"
             :close-on-press-escape="false"
             width="70%">
    <el-form :model="subData"
             label-position="right"
             label-width="150px"
             ref="formModelRef"
             :rules='formModelRules'>
      <el-form-item label="主题病症：" prop="themeIds">
        <el-select v-model="subData.themeIds"
                   filterable
                   clearable
                   multiple
                   class="w-300"
                   placeholder="请选择主题病症">
          <el-option v-for="item in subjectDiseaseDataSource"
                     :key="item.id"
                     :label="item.name"
                     :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="心电图:">
          <vue-neditor-wrap :destroy="true"
                            v-model="subData.electrocardiographic"
                            :config="myConfig"></vue-neditor-wrap>
      </el-form-item>
      <el-form-item label="肝肾功能:">
          <vue-neditor-wrap :destroy="true"
                            v-model="subData.hepatorenalFunction"
                            :config="myConfig"></vue-neditor-wrap>
      </el-form-item>
      <el-form-item label="其他需知:">
          <vue-neditor-wrap :destroy="true"
                            v-model="subData.otherNotice"
                            :config="myConfig"></vue-neditor-wrap>
      </el-form-item>
      <el-form-item label="健康处方:">
          <vue-neditor-wrap :destroy="true"
                            v-model="subData.healthPrescription"
                            :config="myConfig"></vue-neditor-wrap>
      </el-form-item>
    </el-form>
    <p align="center">
      <el-button @click="modalClose"
                 type="info">取 消
      </el-button>
      <el-button type="primary"
                 v-prevent-re-click
                 @click="handleSave()">保 存
      </el-button>
    </p>

  </el-dialog>
</template>

<script>
import VueNeditorWrap from "vue-neditor-wrap";

export default {
  name: "dialongMeasure",
  props: {
    dataObj: {
      type: Object,
      default: {}
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      title: '新 增',
      subData: {
        id: null,
        themeIds: [],
        electrocardiographic: '',
        hepatorenalFunction: '',
        otherNotice: '',
        healthPrescription: '',
      },
      subjectDiseaseDataSource: [],
      myConfig: {
        // 你的UEditor资源存放的路径,相对于打包后的index.html
        UEDITOR_HOME_URL: this.api.uEditorHomeUrl,
        // 编辑器不自动被内容撑高
        autoHeightEnabled: false,
        // 初始容器高度
        initialFrameHeight: '418',
        // 初始容器宽度
        initialFrameWidth: '100%',
        // 关闭自动保存
        enableAutoSave: false,
        scaleEnabled: true
      },
      formModelRules: {
        themeIds: [{required: true, message: '请选择主题病症', trigger: 'blur'},],
      }
    }
  },
  created() {
    this.getSubjectDiseaseList()
    this.subData=Object.assign(this.subData,this.dataObj)
  },
  methods: {
    modalClose() {
      this.$emit('update:visible', false);
    },
    //查询列表
    getSubjectDiseaseList() {
      this.post(this.api.cooperationHospital.getSubjectDiseaseList, {
        searchType: 1,
        knowledgeMeasureId:this.dataObj.id
      }).then((res) => {
        this.loading = false
        if (res.data.code === '200') {
          this.subjectDiseaseDataSource = res.data.object

        }
      })
    },
    handleSave() {
      this.$refs.formModelRef.validate(valid => {
        if (valid) {
          this.post(this.api.cooperationHospital.updateMeasure, this.subData).then((res) => {
            if (res.data.code === '200') {
              this.$message.success('保存成功')
              this.modalClose()
              this.$parent.getList()
            }
          })
        }
      })
    }

  },
  components: {
    VueNeditorWrap
  }
}
</script>

<style scoped>

</style>
